import hashlib
import os
import time

from faker import Faker


def sleep(n_secs):
    time.sleep(n_secs)


from openpyxl import load_workbook

def get_flie_path(file_name):
    base_path = os.path.dirname(__file__)  # util相关路径
    file_path = os.path.join(base_path, 'data', file_name)
    return file_path

#[[],[]]
##[(),()]
def get_excel_to_list(filename, header=True):
    # 加载工作簿
    wb = load_workbook(get_flie_path(filename))
    # 获取默认的工作表
    ws = wb.active
    # 创建一个空列表来保存所有的行数据
    data = []
    if header == True:
        min_row = 2
    else:
        min_row = 1
    # 遍历工作表中的每一行
    for row in ws.iter_rows(min_row=min_row, values_only=True):
        # 将每行转换为列表并添加到总的列表中
        data.append(row)
    return data

def covert_str(input):
    if isinstance(input,int):
        return str(input)
    return input

def getmd5_list(n):
  md5_list=[]
  fake = Faker('zh_CN')
  for i in range(n):
      current_timestamp_seconds = time.time()
      # 将秒转换为毫秒
      current_timestamp_milliseconds = int(current_timestamp_seconds * 1000)
      phone_number = fake.phone_number()
      tosign = f'{phone_number}testfan{current_timestamp_milliseconds}'
      md5_list.append(('testfan',phone_number,current_timestamp_milliseconds,getMd5(tosign)))
  return md5_list

def getMd5(data):
  # 创建一个md5哈希对象
  md5_hash = hashlib.md5()

  # 更新哈希对象，传入需要哈希的数据
   # 注意：如果你的数据不是字节类型，需要先将其编码为字节
  md5_hash.update(data.encode('utf-8'))

    # 获取哈希值的十六进制表示
  digest = md5_hash.hexdigest()
  return digest


def response_decode(response):
    print("----------------")
    print(response)
    print(response.resp_obj)  # requests.response
    response.resp_obj.encoding = "utf-8"

if __name__ == '__main__':
    #print(get_excel_to_list('case.xlsx'))
    print(getmd5_list(3))